﻿using DataAccess;
using Entity;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Business
{
    public class OrderdetailsBusiness
    {
        public DataTable GetUserAllData(UsersEntity ue)
        {
            DataTable dt = null;
            string query = "select * from orderdetails where username = @username";
            string[] paras = { "@username" };
            object[] values = { ue.Username };
            dt = DA.GetDataTable(query, CommandType.Text, paras, values);
            return dt;
        }

        public DataTable GetAllData()
        {
            DataTable dt = null;
            string query = "select * from orderdetails";
            dt = DA.GetDataTable(query, CommandType.Text, null, null);
            return dt;
        }

        public DataTable SearchAllData(OrderdetailsEntity oe)
        {
            DataTable dt = null;
            string query = "select * from orderdetails where productname like @productname";
            string[] paras = { "@productname" };
            object[] values = { "%" + oe.Productname + "%" };
            dt = DA.GetDataTable(query, CommandType.Text, paras, values);
            return dt;
        }

        public int AddOrderdetail(OrderdetailsEntity oe)
        {
            int res = 0;
            string query = "insert into orderdetails values (@orderid,@username,@productname,@quantity,@amount)";
            string[] paras = { "@orderid", "@username", "@productname", "@quantity", "@amount" };
            object[] values = { oe.Orderid, oe.Username, oe.Productname, oe.Quantity, oe.Amount };
            res = DA.ExcuteSql(query, CommandType.Text, paras, values);
            return res;
        }

        public int DeleteOrderdetail(OrderdetailsEntity oe)
        {
            int res = 0;
            string query = "delete from orderdetails where orderdetailid = @orderdetailid";
            string[] paras = { "@orderdetailid" };
            object[] values = { oe.Orderdetailid };
            res = DA.ExcuteSql(query, CommandType.Text, paras, values);
            return res;
        }

        public int DeleteMoreOrderdetail(string sql)
        {
            int res = 0;
            string query = "delete from orderdetails where 1>1 " + sql;
            res = DA.ExcuteSql(query, CommandType.Text, null, null); ;
            return res;
        }
    }
}
